cd "C:\Users\Peter\Dropbox\Dissertation\Dataset\outputs"
**still do options for xtgee, change islamist to islamist_three*

twoway (bar mean Model) (rcap uppercl lowercl Model), xlabel(1 "Religion-State" 2 "Alliance" 3 "Affinity" 4 "Aid" )

**main models**
xtset, clear
xtset ccode year
xtgee  CTCS relstate5yrvary, corr(ar 1) robust
outreg2 using mainmodels.doc, word dec(2) label
xtgee   CTCS  relstate5yrvary terrortwoyear smallWC_ loggdp islamist_three, corr(ar 1) robust
outreg2 using mainmodels.doc, word dec(2) label append
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using mainmodels.doc, word dec(2) label append
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using mainmodels.doc, word dec(2) label append

**regions, time periods, and conflicts**
xtgee  CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three  Africa SouthCentralAsia SoutheastAsia MiddleEast, corr(ar 1) robust
outreg2 using regiontimeperiodconflict.doc, word dec(2) label
xtgee  CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three if IraqAfghanistan==0, corr(ar 1) robust
outreg2 using regiontimeperiodconflict.doc, word dec(2) label append
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three  pre911 _911, corr(ar 1) robust
outreg2 using regiontimeperiodconflict.doc, word dec(2) label append
**subindexes, **

xtgee   Intl_avg relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade ,  corr(ar 1) robust
outreg2 using subindexes.doc, word dec(2) label 
xtgee  Dom_avg  relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade ,  corr(ar 1) robust
outreg2 using subindexes.doc, word dec(2) label append



**robustness checks***

**alt islamist measures**
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade sum_islamist , corr(ar 1) robust
outreg2 using altislamist.doc, word dec(2) label
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade any_islamist , corr(ar 1) robust
outreg2 using altislamist.doc, word dec(2) label append

**mean for entire period, different dataset**
use "C:\Users\Peter\Dropbox\Dissertation\Dataset\data\Dataset wide.dta", clear
reg  avgctcs avgrelstate avggdp avgaid avgtrade avgaffinity avgterror, cluster(ccode)
outreg2 using wholeperiod.doc, word dec(2) label
use "C:\Users\Peter\Dropbox\Dissertation\Dataset\data\CT dataset 125.dta", clear

**alt relstates**
xtgee   CTCS  relstatevarying alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using disaggrelstate.doc, word dec(2) label
xtgee   CTCS   relstate1 relstate4 relstate2 relstate3 alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using disaggrelstate.doc, word dec(2) label

xtgee   CTCS  relstate alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altrelstate.doc, word dec(2) label 
xtgee   CTCS relstatenowc alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altrelstate.doc, word dec(2) label append
xtgee   CTCS  relstate3level alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altrelstate.doc, word dec(2) label append

**alt models**
reg   CTCS  relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, cluster(region)
outreg2 using altmodels.doc, word dec(2) label 
xtset, clear
xtset region ccodeyear
xtreg   CTCS relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, fe 
outreg2 using altmodels.doc, word dec(2) label append
xtset, clear
xtset ccode year
xtreg   CTCS relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, re mle 
outreg2 using altmodels.doc, word dec(2) label append

xtgee   CTCS  relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(exc)
outreg2 using altmodels2.doc, word dec(2) label replace
xtmixed CTCS relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_ loggdp aidgdppc trade islamist_three || ccode: relstate5yrvary , cov(uns)
outreg2 using altmodels2.doc, word dec(2) label append

**alternate DVs**
xtgee   CTCSx_count  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs.doc, word dec(2) label replace
xtgee   CTCSx_oldversion  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs.doc, word dec(2) label append
xtgee   PCAdiff  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs.doc, word dec(2) label append
xtgee   CTCS_nomiss  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs.doc, word dec(2) label append

xtgee   CTCS_sum  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs2.doc, word dec(2) label 
xtgee   CavgX  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs2.doc, word dec(2) label append
xtgee   NCavgX  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs2.doc, word dec(2) label append
xtgee   CTCS_p  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altdvs2.doc, word dec(2) label append


*logit*
xtlogit CTCSx_dic relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, re
outreg2 using logit.doc, word dec(2) label
xtgee poscoop relstate5yrvary  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, family(binomial) link(logit) corr(ar 1) robust
outreg2 using logit.doc, word dec(2) label append

**alternate controls**
xtgee   CTCS relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i loggdp aidgdppc trade islamist_three politytwo, corr(ar 1) robust
outreg2 using altcontrol.doc, word dec(2) label
xtgee   CTCS relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i loggdp aidgdppc trade islamist_three democracy, corr(ar 1) robust
outreg2 using altcontrol.doc, word dec(2) label append
xtgee   CTCS relstate5yrvary alliance usmid econaidpc  alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp trade islamist_three , corr(ar 1) robust
outreg2 using altcontrol.doc, word dec(2) label append
xtgee   CTCS relstate5yrvary alliance usmid milaidpc alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp  trade islamist_three , corr(ar 1) robust
outreg2 using altcontrol.doc, word dec(2) label append

xtgee  CTCS relstate5yrvary alliance usmid maxdr terrorismdeaths s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altcontrol2.doc, word dec(2) label 
xtgee  CTCS relstate5yrvary alliance usmid maxdr intensity s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altcontrol2.doc, word dec(2) label append
xtgee   CTCS relstate5yrvary alliance usmid maxdr terrorismlevel s3un4608i smallWC_  loggdp aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altcontrol2.doc, word dec(2) label append 
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  cinc aidgdppc trade islamist_three, corr(ar 1) robust
outreg2 using altcontrol2.doc, word dec(2) label append

xtgee   CTCS relstate5yrvary alliance usmid econaid_  maxdr terrortwoyear s3un4608i smallWC_  loggdp trade islamist_three , corr(ar 1) robust
outreg2 using altcontrols3.doc, word dec(2) label 
xtgee   CTCS relstate5yrvary alliance usmid milaid_   maxdr terrortwoyear s3un4608i smallWC_  loggdp  trade islamist_three , corr(ar 1) robust
outreg2 using altcontrols3.doc, word dec(2) label append
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using altcontrols3.doc, word dec(2) label append

xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three RussChinally, corr(ar 1) robust
outreg2 using altcontrols4.doc, word dec(2) label 
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade , corr(ar 1) robust
outreg2 using altcontrols4.doc, word dec(2) label append

**removing Somalia and Syria**
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three if somalia == 0, corr(ar 1) robust
outreg2 using syriasomalia.doc, word dec(2) label 
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three if syria == 0, corr(ar 1) robust
outreg2 using syriasomalia.doc, word dec(2) label append
**gallup and pew data**

xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three gallup, corr(ar 1) robust
outreg2 using usapproval.doc, word dec(2) label
xtgee   CTCS  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three pew, corr(ar 1) robust
outreg2 using usapproval.doc, word dec(2) label append


**factorsubindexes, **
xtgee   TetraCoopfactor1  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using factors.doc, word dec(2) label
xtgee   TetraCoopfactor2  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using factors.doc, word dec(2) label append
xtgee   TetraNoncoopfactor1  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using factors.doc, word dec(2) label append
xtgee   TetraNoncoopfactor2  relstate5yrvary alliance usmid maxdr terrortwoyear s3un4608i smallWC_  loggdp aidgdppc trade islamist_three , corr(ar 1) robust
outreg2 using factors.doc, word dec(2) label append

*graphs*
tsline avg_CTCS if cname== "Pakistan" & year > 1996, ytitle("Average Counterterrorism Cooperation") xlabel(1996 2001 2005 2009)
tsline EuropeCT_annual AfricaCT_annual MENACT_annual AsiaCT_annual, ytitle("Average Counterterrorism Cooperation") xlabel(1996 2002 2005 2009)
by ccode, sort: egen mean_CTCS_byC = mean(CTCS)
by ccode, sort: egen mean_relstate_byC = mean(relstate5yrvary)
twoway (scatter mean_CTCS mean_relstate, ytitle(Counterterrorism Cooperation) xtitle(Religion-State)) (lfit mean_CTCS mean_relstate, legend(off)) 

*merge in subs stuff*
label define model 1 "Religion_State" 2 "Alliance" 3 "Aid"
label values model model
twoway (bar mean model) (rcap  uppercl  lowercl model), ytitle(Effect on Counterterrorism Cooperation) xlabel(1 2 3 , valuelabel)


